﻿using CustomerContactSystem.Core.AppServices.Configuration;
using CustomerContactSystem.Core.AppServices.Email;
using CustomerContactSystem.Core.DataAccess.nHibernate;
using CustomerContactSystem.Core.Infrastructure.Configuration;
using CustomerContactSystem.Core.Infrastructure.DataAccess;
using CustomerContactSystem.Core.Infrastructure.Email;
using CustomerContactSystem.Core.Model;
using NHibernate;
using StructureMap;

namespace CustomerContactSystem.WebForms {
    public class StructureMapConfigure {
         public static void Configure() {
             ObjectFactory.Initialize(x =>
                 {
                     x.For<ISession>().Use(y => Global.SessionFactory.GetCurrentSession());
                     x.For<IApplicationSettings>().Use<WebConfigApplicationSettings>();
                     x.For(typeof(INhibernateRepository<>)).Use(typeof(NhibernateRepository<>));
                     x.For<IEmailService>().Use<SmtpEmailService>();

                     x.SetAllProperties(y =>
                         {
                             y.OfType<INhibernateRepository<User>>();
                             y.OfType<INhibernateRepository<Customer>>();
                             y.OfType<INhibernateRepository<Department>>();
                             y.OfType<INhibernateRepository<Enquiry>>();
                             y.OfType<INhibernateRepository<EnquiryCategory>>();
                             y.OfType<INhibernateRepository<EnquiryClassification>>();
                             y.OfType<INhibernateRepository<EnquiryClosure>>();
                             y.OfType<INhibernateRepository<EnquiryCommitmentClosure>>();
                             y.OfType<INhibernateRepository<EnquiryCurrentReferral>>();
                             y.OfType<INhibernateRepository<EnquiryDeletion>>();
                             y.OfType<INhibernateRepository<EnquiryFirstReferral>>();
                             y.OfType<INhibernateRepository<EnquiryReferral>>();
                             y.OfType<INhibernateRepository<EnquirySource>>();
                             y.OfType<INhibernateRepository<Rep>>();
                             y.OfType<INhibernateRepository<Tag>>();
                             y.OfType<INhibernateRepository<UserGroup>>();
                             y.OfType<INhibernateRepository<UserRole>>();
                             y.OfType<IApplicationSettings>();
                             y.OfType<IEmailService>();
                         });
                 });
         }
    }
}